<?php
session_cache_expire(999999999);
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
include "../operations/connection_ajax.php";
	
		if(isset($_SESSION['lang']))
		$lang=$_SESSION['lang'];	
	if (empty($lang) || $lang == "EN") {
		$value = "../value/value_en.php";
	} else if($lang == "VN") {
		$value = "../value/value_vn.php";
	}
	else {
		$value = "../value/value_kr.php";
	}
	
	
	include($value);
$list=$_SESSION['sortem'];
$str=$_REQUEST['strs'];
$_SESSION['sortemn']=$str;	
$str1=$str;	
if($str=="em.FullName")
	$str1="SUBSTRING_INDEX(em.FullName,' ', -1)";
$order_by = " order by ".$str1." ".$list[$str];


if ( !isset($_REQUEST['pages'] ))
	{
    	$page = 1 ;
	}else{
		$page = $_REQUEST['pages'] ;
}
	if (isset($_REQUEST['searchAll'])) {
		unset($_SESSION['searchstring']);
	}
	
	if (isset($_SESSION['searchstring'])) {
		$searchstring = $_SESSION['searchstring'];
	}
	else{
		$searchstring = '';
	}

	$rows_per_page = 10;
	$page_start = ( $page - 1 ) * $rows_per_page; 
	$page_end = $page * $rows_per_page;
	
	
$listemployeePage = mysql_query("SELECT em.IDEmployee FROM employee em left JOIN department_lang dpl
	 on em.IDDepartment = dpl.IDDepartment where em.State = 1 and em.IDRole != 1 and dpl.LangID='".$lang."'".$searchstring);

$listemployee = mysql_query("SELECT em.IDEmployee,em.UserName, em.FullName,em.Positionsit,em.Email,em.StartDate ,dpl.DepartmentName, em.Position ,em.Sex, em.IDDepartment,em.Phone,em.Birthday FROM employee em left JOIN department_lang dpl
 on em.IDDepartment = dpl.IDDepartment where em.State = 1 and em.IDRole != 1 and  dpl.LangID='".$lang."' ".$searchstring." ".$order_by." limit ".$page_start.",".$rows_per_page);


$number_of_page_employees = ceil ( mysql_num_rows( $listemployeePage ) / $rows_per_page );

?>
				<tr  class="table_new">
						<td width="3%"><?=$l_no?></td>
		                <td width="15%"><a href="#" onclick="sortem(1,'em.Fullname')"><?=$l_fullname?></a></td>
		                <td width="8%"><a href="#" onclick="sortem(1,'dpl.DepartmentName')"><?=$l_department?></a></td>
		                <td width="8%"><a href="#" onclick="sortem(1,'em.Positionsit')"><?=$l_position?></a></td>
		                <td width="20%"><a href="#" onclick="sortem(1,'em.Email')"><?=$l_email?></a></td>
		                <td width="8%"><a href="#" onclick="sortem(1,'em.Phone')"><?=$l_phone?></a></td>
		                <td width="8%"><a href="#" onclick="sortem(1,'em.Birthday')"><?=$l_birthday?></a></td>
		                <td width="8%"><a href="#" onclick="sortem(1,'em.StartDate')"><?=$l_start_date?></a></td>
		                
		                <td width="20%"><a href="#" onclick="sortem(1,'em.Position')"><?=$l_sitting_position?></a></td>
	                </tr>
<?php 
                unset($_SESSION['lstemps']);
	                $temp_lstemps = array();
	                $i=$page*$rows_per_page;
	                while ($row=mysql_fetch_array($listemployee)){ 
	                	array_push($temp_lstemps, array($row['IDEmployee'],$row['UserName'],$row['FullName'],$row['DepartmentName'],$row['Position'],$row['Sex'],$row['IDDepartment'],$row['StartDate']));
	                	$i++;
					?>
	                <tr>
	                	<td align="center"><?=$i?></td>
		                <td align="center" class="FullName"><?=$row['FullName']?></td>
		                <td align="center"><?=$row['DepartmentName']?></td>
		                <td align="center" class="IDEmployee"><?=$row['Position']?><input type="hidden" value="<?=$row['IDEmployee']?>"/></td>
		                <td align="center"><?=$row['Email']?></td>
		                <td align="center"><?=$row['Phone']?></td>
		                <td align="center"><?=$row['Birthday']?></td>
		                <td align="center"><?=$row['StartDate']?></td>
		                <td align="left">
		                
						<?php 
						if(isset($row['Positionsit'])){
							if($row['Positionsit']!=""){
								
								$p=explode('-', $row['Positionsit']);
								echo "Lau :".$p[0]." - Phong :".$p[1]." - Vi tri :".$p[2];
							}
								
						}
						
						?>
		                
		                </td>
	                </tr>
	                <?php }
	                $_SESSION['lstemps'] = $temp_lstemps;
	                $temp_lstemps = null;
	                ?>
	                <tr class="trfoot">
	                    	<td class="rf-dt-ftr-c" scope="colgroup" colspan="9">
	                        	<div style="text-align: center; width: 100%">
	                            	<span class="rf-ds">
															
															<?php if ( $number_of_page_employees > 1 ) 
															{ 
																if ($page==1)
																	$p=2;
																else if ($page==$number_of_page_employees)
																	$p=$number_of_page_employees-1;
																else $p=$page;
																if($page!=1){?>
																	<a onclick="paging(1,'<?=$str?>')" ><span class='button_next'><?php echo "<<<";?></span> </a>
																	<a onclick="paging(<?=($page-1)?>,'<?=$str?>')" ><span class='button_next'><?php echo "<<";?></span> </a>
																<?php  }
																else{
																	echo "<span class='button_next'><<<</span>"; 
																	echo "<span class='button_next'><<</span>";
																}
																for ( $i = $p-1; $i <= $p+1; $i++ ) {	
																		if ($i<=$number_of_page_employees && $i>0)
																		
																			if ($i==$page){
																				echo "<span class='button_next' style='color: #000'><i>".$i."</i></span>"; 
																			}else{
																			?>
																				<a onclick="paging(<?=$i?>,'<?=$str?>')" ><span class="button_next">
																				<?php 
																				echo $i;
																				?>
																				</span> </a>
																			<?php 
																			}
																		?>
																	
																<?php 
																		}
																	
																	if($page!=$number_of_page_employees){ ?>
																		<a onclick="paging(<?=($page+1)?>,'<?=$str?>')"><span class='button_next'><?php echo ">>";?></span> </a>
																		<a onclick="paging(<?=($number_of_page_employees)?>,'<?=$str?>')" ><span class='button_next'><?php echo ">>>";?></span> </a>
																	<?php }
																	else{
																		echo "<span class='button_next'>>></span> ";
																		echo "<span class='button_next'>>>></span> ";
																	}
																}
															
																
																?>
																													
														</span>
														</div>
														</td>
	                    </tr>

<?php 
mysql_close($connection_ajax);
?>